package com.ukao.steward.dialog;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ukao.steward.R;
import com.ukao.steward.base.BaseDialogFragment;
import com.ukao.steward.util.CheckUtils;
import com.ukao.steward.util.DensityUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

import static com.ukao.steward.base.BaseFragment.ARG_PARAM2;
import static com.ukao.steward.consts.Constant.ARG_PARAM1;
import static com.ukao.steward.consts.Constant.ARG_PARAM3;
import static com.ukao.steward.consts.Constant.ARG_PARAM4;

/**
 * Created by ukaodev on 2017/6/2.
 */

public class AmountDetailDialogFragment extends BaseDialogFragment {

    Unbinder unbinder;
    @BindView(R.id.close_btn)
    ImageView closeBtn;
    @BindView(R.id.title)
    TextView title;
    @BindView(R.id.orderPrice_tv)
    TextView orderPriceTv;
    @BindView(R.id.takeCarriage_tv)
    TextView takeCarriageTv;
    @BindView(R.id.sendCarriage_tv)
    TextView sendCarriageTv;
    @BindView(R.id.modifyPrice_tv)
    TextView modifyPriceTv;
    @BindView(R.id.modifyPrice_layout)
    LinearLayout modifyPriceLayout;
    @BindView(R.id.close_btn1)
    Button closeBtn1;


    private String orderPrice;
    private String sendCarriage;
    private String takeCarriage;
    private String modifyPrice;

    public static AmountDetailDialogFragment newInstance(String orderPrice, String sendCarriage, String takeCarriage, String modifyPrice) {
        AmountDetailDialogFragment fragment = new AmountDetailDialogFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, orderPrice);
        args.putString(ARG_PARAM2, sendCarriage);
        args.putString(ARG_PARAM3, takeCarriage);
        args.putString(ARG_PARAM4, modifyPrice);
        fragment.setArguments(args);
        return fragment;
    }


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            orderPrice = getArguments().getString(ARG_PARAM1);
            sendCarriage = getArguments().getString(ARG_PARAM2);
            takeCarriage = getArguments().getString(ARG_PARAM3);
            modifyPrice = getArguments().getString(ARG_PARAM4);

        }

    }


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.dialog_amount_detail_layuou, container, false);
        unbinder = ButterKnife.bind(this, view);
        return view;
    }


    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView();
        initListener();
    }

    @Override
    protected void initView() {
        title.setText("金额明细");
        orderPriceTv.setText("￥" + orderPrice);
        takeCarriageTv.setText("￥" + takeCarriage);
        sendCarriageTv.setText("￥" + sendCarriage);
        modifyPriceLayout.setVisibility(CheckUtils.isEmpty(modifyPrice) ? View.GONE : View.VISIBLE);
        modifyPriceTv.setText("￥" + modifyPrice);
        int with = (int) (DensityUtils.getScreenW() - DensityUtils.getScreenW() * 0.14);
        setIsWithWrap(false);
        setWidth(with);
        setHeight((int) (with * 0.68));

    }

    @Override
    protected void initListener() {
        super.initListener();


    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        if (mDialogSubmitListener!=null){
            mDialogSubmitListener.onSubmitClick(R.id.close_btn,"");
        }
        unbinder.unbind();
    }


    @OnClick({R.id.close_btn, R.id.close_btn1})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.close_btn:
                dismiss();
                break;
            case R.id.close_btn1:
                dismiss();
                break;
        }
    }
}
